import { AppDispatch, AppThunk, RootState } from "@/store"
import { useEffect } from "react"
import { useDispatch, useSelector } from "react-redux"

export function useinitstate<StateName extends keyof RootState>(action: () => AppThunk, module: StateName) {

  const dis = useDispatch<AppDispatch>()
  useEffect(() => {
    dis(action())
  }, [])

  const data = useSelector((state: RootState) => state[module])
  return data
}
